//--------------------------------------------------------------
//
// Qizhi Zhang 
// ezhung@gmail.com
// http://www.moorwind.com
//
//--------------------------------------------------------------
package reader.model.vo
{
	import __AS3__.vec.Vector;
	
	import mx.formatters.DateFormatter;
	
	public class MediaVO extends SelectAbleVO
	{
		public static const MEDIA_IMAGE:int = 0;
		public static const MEDIA_VIDEO:int = 1;
		public static const MEDIA_AUDIO:int = 2;
		public static const MEDIA_TYPE_UNKNOW:String = "unknown";
		
		private var _mid:int;
		public function get mid():int
		{
			
			return _mid;
		}
		public function set mid(value:int):void
		{
			_mid = value;
		}
		
		private var _type:int;
		public function get type():int
		{
			
			return _type;
		}
		public function set type(value:int):void
		{
			_type = value;
		}
		
		private var _uri:String;
		public function get uri():String
		{
			
			return _uri
		}
		public function set uri(value:String):void
		{
			_uri = value;
		}
		
		private var _name:String;
		public function get name():String
		{
			
			return _name
		}
		public function set name(value:String):void
		{
			_name = value;
		}
		
		private var _platform:String;
		public function get platform():String
		{
			
			return _platform
		}
		public function set platform(value:String):void
		{
			_platform = value;
		}
		
		private var _ext:String;
		public function get ext():String
		{
			
			return _ext
		}
		public function set ext(value:String):void
		{
			_ext = value;
		}
		
		private var _date:Date;
		public function get date():Date
		{
			
			return _date;
		}
		public function set date(value:Date):void
		{
			_date = value;
		}
		
		public function MediaVO(photo:PhotoVO = null)
		{
			if(photo)
			{
				this.type = MEDIA_IMAGE;
				this.uri = photo.imageuri;
				this.name = photo.caption;
				this.ext = getExtByURI(photo.imageuri);
				this.date = new Date();
			}
		}
		
		public function get dateTime():Number
		{
			return date.getTime();
		}
		
		public function get dateFromat():String
		{
			var format:DateFormatter = new DateFormatter();
			format.formatString = "YYYY/MM/DD";
			return format.format(date);
		}
		
		//----------------------------------------------------------------------------
		//
		// methods
		//
		//----------------------------------------------------------------------------
		
		public static function getExtByURI(uri:String):String
		{
			if(!uri || uri=="") return MEDIA_TYPE_UNKNOW;
			
			var a:Array = uri.split(".");
			var r:String
			try
			{
				r = a[a.length - 1].toLowerCase();
			}
			catch(e:Error)
			{
				r = MEDIA_TYPE_UNKNOW;
			}
			return r;
		}
		
		//----------------------------------------------------------------------------
		//
		// Convert Vector to Array
		//
		//----------------------------------------------------------------------------
		
		public static function VectorToArray(v:Vector.<MediaVO>):Array/* of MediaVO */
		{
			var a:Array = [];
			for each(var i:MediaVO in v)
			{
				a.push(i);
			}
			return a;
		}
		
		public static function ArrayToVector(a:Array/* of MediaVO */):Vector.<MediaVO>
		{
			var v:Vector.<MediaVO> = new Vector.<MediaVO>();
			for each(var i:MediaVO in a)
			{
				v.push(i);
			}
			return v;
		}
	}
}